package com.yc.store.biz;

import com.yc.store.bean.Bill;
import com.yc.store.bean.BillItem;
import com.yc.store.mapper.BillItemMapper;
import com.yc.store.mapper.BillMapper;
import com.yc.store.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/4/27
 * Email haijunzhou@hnit.edu.cn
 */
@Service
public class BillBIz {

    @Autowired
    BillMapper billMapper;
    @Autowired
    BillItemMapper billItemMapper;

    @Transactional(rollbackFor = BizExeption.class)
    public void addBill(Bill bill) throws BizExeption{
        Utils.check(Utils.isEmpty(bill.getType()),"订单类型不能为空");
        Utils.check(Utils.isEmpty(bill.getCustom()),"客户单位不能为空");
        Utils.check(Utils.isEmpty(bill.getItems()),"商品不能为空");
        // 其他验证自行扩展
        billMapper.insert(bill);
        for (BillItem item : bill.getItems()) {
            item.setBid(bill.getId());
            billItemMapper.insert(item);
        }
    }
}
